<?php

namespace App\Http\Controllers\Admin;

use App\Http\Config\ErrorCode;
use Illuminate\Http\Request;
use App\Models\Admin\WorkOrder;

class WorkOrderController extends BaseController
{
    public function __construct(Request $request)
    {
        parent::__construct($request);
    }

	public function getDataList(Request $request)
    {
        if (!$request->ajax()) {
            $this->returnData = ErrorCode::$admin_enum["request_error"];
            return response()->json($this->returnData);
        }
        $type = '1,3';
        if($this->AU['id']==1){
            $type = '';
        }
        $pageno = $request->post('page_no') ? $request->post('page_no') : 1;
        $pagesize = $request->post('page_size') ? $request->post('page_size') : 10;
        $searchFilter = array(
            'sortName' => $request->post('sortName','id'),                                                  //排序列名
            'sortOrder' => $request->post('sortOrder','desc'),                                              //排序（desc，asc）
            'pageNumber' => $pageno,                                                                                    //当前页码
            'pageSize' => $pagesize,                                                                                    //一页显示的条数
            'start' => ($pageno-1) * $pagesize,                                                                         //开始位置
            'type' => $type,                                                                                            //搜索类型
            'searchKey' => trim($request->post('search',''))                                                //搜索条件
        );
        $workOrderModel = new WorkOrder();
        $data = $workOrderModel->getWorkOrderListWithFilter($searchFilter);
        $this->returnData['data'] = $data;
        return response()->json($this->returnData);
    }

	//处理问题
	public function update(Request $request)
    {
        if (!$request->ajax()) {
            $this->returnData = ErrorCode::$admin_enum["request_error"];
            return response()->json($this->returnData);
        }
        $id = $request->id;
        if(empty($id)){
            $this->returnData = ErrorCode::$admin_enum["params_error"];
            $this->returnData["msg"] = "参数id不存在";
            return response()->json($this->returnData);
        }
        $data['remarks'] = $request->post("remarks", '');
        $data['status'] = 1;
        $problemModel = new WorkOrder();
        $res = $problemModel->workOrderUpdate($id,$data);
        if(!$res){
            $this->returnData = ErrorCode::$admin_enum["error"];
            $this->returnData['msg'] = '处理失烦烦烦败';
            return response()->json($this->returnData);
        }
        $this->returnData['msg'] = '处理成功';
        return response()->json($this->returnData);
	}
}